var webpack = require('webpack');

var CleanWebpackPlugin = require('clean-webpack-plugin');

var path = require("path");
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, "app");
var TMP_PATH = path.resolve(ROOT_PATH, "tmp");
var BUILD_PATH = path.resolve(ROOT_PATH, "dist");
var NODE_MODULES = path.resolve(ROOT_PATH, "node_modules");

module.exports = {
    entry: {
        app: [
            'webpack-dev-server/client?http://0.0.0.0:8000', // WebpackDevServer host and port
            'webpack/hot/only-dev-server', // "only" prevents reload on syntax errors
            path.resolve(APP_PATH, "./index.js") // Your appʼs entry point
        ]
    },
    devtool: 'source-map',
    output: {
        path: TMP_PATH,
        publicPath: "/assets/",
        filename: '[name].js'
    },
    devServer: {
        contentBase: APP_PATH,
        port: 8000,
        historyApiFallback: true,
        hot: true,
        inline: true,
        progress: true,
        proxy: {
            '/api/*': {
                // target: 'http://localhost:8080/',
                target: 'http://traykai.xicp.net:18080/',
                pathRewrite: {
                    '^/api': '/evm'
                },
                secure: false
            }
        }
    },
    module: {
        //和loaders一样的语法，很简单
        perLoaders: [
            {
                test: /\.jsx$|\.js/,
                exclude: /(node_modules|bower_components)/,
                loader: 'eslint',
            }
        ],
        loaders: [
            {
                test: /\.html$/,
                loader: "html"
            },
            {
                test: /\.css$/,
                loaders: ["style", "css"]
            },
            {
                test: /\.scss$/,
                loaders: ["style", "css", "sass"]
            },
            {
                test: /\.less$/,
                loaders: ["style", "css", "less"]
            },
            {
                test: /\.jsx$|\.js$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'stage-0', 'react'],
                    plugins: [
                        ['import', [{
                            libraryName: "antd"/*,
                            style: true*/
                        }]]
                    ],
                    cacheDirectory: true
                }
            },
            {
                test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
                loader: "url?limit=50000"
            }
        ]
    },
    sassLoader: {
        data: "$env: " + process.env.NODE_ENV + ";"
    },
    plugins: [
        new webpack.DllReferencePlugin({
            context: __dirname,
            manifest: require(path.resolve(APP_PATH, 'lib/vendors-manifest.json'))
        }),
        new CleanWebpackPlugin(["dist", "tmp"]),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ]
};